////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Project Name: ARS Logs Reader
// Version: 1.0
// File Name: 'objectsindex.h'
//
////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef __INDEXVIEW_H
#define __INDEXVIEW_H

///////// Include files ////////////////////////////////////////////////////////////////////////////

#include <QTableView>
#include <QSortFilterProxyModel>
#include <QItemDelegate>

#include <dynamicmodel.h>
#include <viewwidget.h>
#include <viewinterface.h>

///////// Class 'ObjectsIndex' declaration /////////////////////////////////////////////////////////

Q_DECLARE_METATYPE(Qt::CheckState)

class IndexViewModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    IndexViewModel(ObjectsIndex * index, QObject * parent = 0);

    Qt::ItemFlags flags( const QModelIndex & index ) const;

private:
    ObjectsIndex * m_index;
};

class IndexViewDataModel : public IndexViewModel
{
    Q_OBJECT

public:
    IndexViewDataModel(ObjectsIndex * index, QObject * parent = 0);

    ARSDummyObject * objectForIndex( const QModelIndex & index ) const;
    int rowCount( const QModelIndex & parent ) const;
    int columnCount( const QModelIndex & parent ) const;
    QVariant data( const QModelIndex & index, int role ) const;
    QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;

private:
    ARSDummyObjectList m_list;
};

class IndexViewWorkflowModel : public IndexViewModel
{
    Q_OBJECT

public:
    IndexViewDataModel(ObjectsIndex * index, QObject * parent = 0);

    ARSDummyObject * objectForIndex( const QModelIndex & index ) const;
    int rowCount( const QModelIndex & parent ) const;
    int columnCount( const QModelIndex & parent ) const;
    QVariant data( const QModelIndex & index, int role ) const;
    QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;

private:
    ARSDummyObjectList m_list;
};

class IndexViewGuideModel : public IndexViewModel
{
    Q_OBJECT

public:
    IndexViewGuideModel(ObjectsIndex * index, QObject * parent = 0);

    ARSDummyObject * objectForIndex( const QModelIndex & index ) const;
    int rowCount( const QModelIndex & parent ) const;
    int columnCount( const QModelIndex & parent ) const;
    QVariant data( const QModelIndex & index, int role ) const;
    QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;

private:
    ARSDummyObjectList m_list;
};

class ObjectsListView : public QTableView
{
    Q_OBJECT

public:
    enum ViewType
    {
        Data,
        Workflow,
        Guide
    }

    ObjectsListView( QWidget * parent = 0, ViewType type );
    void setIndex( ObjectsIndex * index );
    void setFilterString( const QString & text );

signals:
    void objectDoubleClicked( ARSDummyObject * object );

public slots:
    void itemDoubleClicked( const QModelIndex & index );

private:
    ObjectsIndex * m_index;
    QSortFilterProxyModel * m_filterModel;
    QString m_filterString;
    ViewType m_type;
};

class ObjectsListTypeDelegate : public QItemDelegate
{
    Q_OBJECT

public:
    ObjectsListTypeDelegate( QObject * parent = 0 );
    void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
};

class IndexViewWidet : public DynamicViewWidget
{
    Q_OBJECT

public:
    IndexViewWidet(QWidget * parent = 0);

    QString pluginName() const;
    void connectToolBarItems(const ToolBarItemList & items);
    void disconnectToolBarItems(const ToolBarItemList & items);
    void adjustToolbar(const ToolBarItemList & itemsList) const;
    void setModel(DynamicModel * model);

signals:
    void openItem(ARSExecItem * item);

private:
    QTabWidget * m_tabWidget;
    ObjectsListView * m_view;
};

class IndexViewPlugin : public QObject,
                        public ViewPluginInterface
{
    Q_INTERFACES(PluginInterface ViewPluginInterface)
    Q_OBJECT

public:
    IndexViewPlugin(QObject * parent = 0);

    QString name()const;
    QString description()const;
    bool loadSettings();
    QString viewName()const;
    ViewWidget::ViewType viewType() const;
    QIcon icon(bool active)const;
    ViewWidget * createView(QWidget * parent = 0)const;
    ToolBarItemList toolBarItems(QObject * parent)const;
    SettingsWidget * settingsWidget(QWidget * parent = 0)const;
    void appEvent(AppEvent *event);
};

////////////////////////////////////////////////////////////////////////////////////////////////////

#endif // __INDEXVIEW_H

////////////////////////////////////////////////////////////////////////////////////////////////////
